package c.h.a.m0;

import android.text.format.Formatter;
import android.webkit.MimeTypeMap;
import com.liuzh.deviceinfo.DeviceInfoApp;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Locale;

/* compiled from: FileUtils */
public class j {
    public static String[] a = new String[]{"Byte", "kB", "MB", "GB"};
    public static SimpleDateFormat b = new SimpleDateFormat(g.a, Locale.getDefault());

    public static boolean a(File file) {
        if (file.exists() && file.isFile() && file.canWrite()) {
            return file.delete();
        }
        if (file.isDirectory()) {
            String[] list = file.list();
            if (list == null || list.length == 0) {
                return file.delete();
            }
            for (String str : list) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append(file.getAbsolutePath());
                stringBuilder.append("/");
                stringBuilder.append(str);
                File file2 = new File(stringBuilder.toString());
                if (file2.isFile()) {
                    file2.delete();
                } else {
                    a(file2);
                    file2.delete();
                }
            }
            if (file.exists()) {
                return file.delete();
            }
        }
        return false;
    }

    public static boolean b(File file) {
        if (file.exists()) {
            return file.delete();
        }
        return true;
    }

    public static long c(File file) {
        long j = 0;
        if (!file.exists()) {
            return 0;
        }
        if (file.isFile()) {
            return file.length();
        }
        File[] listFiles = file.listFiles();
        if (listFiles != null) {
            for (File file2 : listFiles) {
                long c;
                if (file2.isDirectory()) {
                    c = c(file2);
                } else {
                    c = file2.length();
                }
                j += c;
            }
        }
        return j;
    }

    public static String d(String str) {
        int lastIndexOf = str.lastIndexOf(46);
        if (lastIndexOf >= 0) {
            str = MimeTypeMap.getSingleton().getMimeTypeFromExtension(str.substring(lastIndexOf + 1).toLowerCase());
            if (str != null) {
                return str;
            }
        }
        return "application/octet-stream";
    }

    public static boolean e(File file) {
        if (file.exists()) {
            return true;
        }
        return file.mkdirs();
    }

    public static String f(long j) {
        return Formatter.formatFileSize(DeviceInfoApp.c, j);
    }
}
